package com.atguigu.edu.controller.front;

import com.atguigu.edu.entity.Course;
import com.atguigu.edu.entity.Teacher;
import com.atguigu.edu.service.CourseService;
import com.atguigu.edu.service.TeacherService;
import com.atguigu.utils.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
//@CrossOrigin
@Api(description = "前台讲师管理",value = "前台讲师管理")
public class TeacherFrontController {
    @Resource
    private TeacherService teacherService;
    @Resource
    private CourseService courseService;
    @GetMapping("/pageInfo/{page}/{limit}")
    public R pageInfo(@PathVariable("page")long page,@PathVariable("limit")long limit){
        Map<String,Object> map=teacherService.pageInfo(page,limit);
        return R.ok().data(map);
    }
    @GetMapping("/get/{id}")
    public R getTeacherById(@PathVariable("id")String id){
        //获取讲师信息
        Teacher teacher = teacherService.getById(id);
        //获取讲师教授的课程信息
        LambdaQueryWrapper<Course> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Course::getTeacherId,id);
        List<Course> courseList = courseService.list(queryWrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }
}
